Asynchronous task management in an on-demand network code execution environment

ABSTRACT

Systems and methods are described for managing asynchronous code executions in an on-demand code execution system or other distributed code execution environment, in which multiple execution environments, such as virtual machine instances, can be used to enable rapid execution of user-submitted code. When asynchronous executions occur, one execution may become blocked while waiting for completion of another execution. Because the on-demand code execution system contains multiple execution environments, the system can efficiently handle a blocked execution by saving a state of the execution, and removing it from its execution environment. When a blocking dependency operation completes, the system can resume the blocked execution using the state information, in the same or different execution environment.

BACKGROUND

Computing devices can utilize communication networks to exchange data.Companies and organizations operate computer networks that interconnecta number of computing devices to support operations or to provideservices to third parties. The computing systems can be located in asingle geographic location or located in multiple, distinct geographiclocations (e.g., interconnected via private or public communicationnetworks). Specifically, data centers or data processing centers, hereingenerally referred to as a “data center,” may include a number ofinterconnected computing systems to provide computing resources to usersof the data center. The data centers may be private data centersoperated on behalf of an organization or public data centers operated onbehalf, or for the benefit of, the general public.

To facilitate increased utilization of data center resources,virtualization technologies allow a single physical computing device tohost one or more instances of virtual machines that appear and operateas independent computing devices to users of a data center. Withvirtualization, the single physical computing device can create,maintain, delete, or otherwise manage virtual machines in a dynamicmanner. In turn, users can request computer resources from a datacenter, including single computing devices or a configuration ofnetworked computing devices, and be provided with varying numbers ofvirtual machine resources.

In some scenarios, virtual machine instances may be configured accordingto a number of virtual machine instance types to provide specificfunctionality. For example, various computing devices may be associatedwith different combinations of operating systems or operating systemconfigurations, virtualized hardware resources and software applicationsto enable a computing device to provide different desiredfunctionalities, or to provide similar functionalities more efficiently.These virtual machine instance type configurations are often containedwithin a device image, which includes static data containing thesoftware (e.g., the OS and applications together with theirconfiguration and data files, etc.) that the virtual machine will runonce started. The device image is typically stored on the disk used tocreate or initialize the instance. Thus, a computing device may processthe device image in order to implement the desired softwareconfiguration.

BRIEF DESCRIPTION OF DRAWINGS

FIG. 1 is a block diagram depicting an illustrative environment in whichan on-demand code execution system can operate, the on-demand codeexecution system including an async controller to manage asynchronouscalls between tasks executing on the on-demand code execution system;

FIG. 2 depicts a general architecture of a computing device providingthe async controller of FIG. 1;

FIGS. 3A and 3B are flow diagrams depicting illustrative interactionsfor handling blocked execution of a task due to an asynchronousdependency by using the async controller of FIG. 1 to suspend executionof the task on the on-demand code execution system;

FIGS. 4A-4C are flow diagrams depicting illustrative interactions formanaging execution of asynchronous task calls in an on-demand codeexecution system based on a deadline associated with the task;

FIG. 5 is a flow chart depicting an illustrative routine for handlingasynchronous task execution in an on-demand code execution system;

FIG. 6 is a flow chart depicting an illustrative routine for managingexecution of asynchronous task calls in an on-demand code executionsystem based on a deadline associated with the task; and

FIG. 7 is a flow chart depicting an illustrative routine for handlingblocked execution of a task due to an asynchronous dependency.

DETAILED DESCRIPTION

Generally described, aspects of the present disclosure relate tohandling execution of asynchronous tasks in an on-demand code executionsystem, and more specifically, to using deadline information associatedwith an asynchronous task to efficiently execute the task, and toreducing the inefficiency of tasks whose execution is blocked due to anasynchronous dependency by suspending execution of the task. Asdescribed in detail herein, an on-demand code execution system mayprovide a network-accessible service enabling users to submit ordesignate computer-executable code to be executed by virtual machineinstances on the on-demand code execution system. Each set of code onthe on-demand code execution system may define a “task,” and implementspecific functionality corresponding to that task when executed on avirtual machine instance of the on-demand code execution system.Individual implementations of the task on the on-demand code executionsystem may be referred to as an “execution” of the task. The on-demandcode execution system can further enable users to trigger execution of atask based on a variety of potential events, such as transmission of anapplication programming interface (“API”) call or a specially formattedhypertext transport protocol (“HTTP”) packet. Thus, users may utilizethe on-demand code execution system to execute any specified executablecode “on-demand,” without requiring configuration or maintenance of theunderlying hardware or infrastructure on which the code is executed.Further, the on-demand code execution system may be configured toexecute tasks in a rapid manner (e.g., in under 100 milliseconds [ms]),thus enabling execution of tasks in “real-time” (e.g., with little or noperceptible delay to an end user). To enable this rapid execution, theon-demand code execution system can include one or more virtual machineinstances that are “pre-warmed” or pre-initialized (e.g., booted into anoperating system and executing a complete or substantially completeruntime environment) and configured to enable execution of user-definedcode, such that the code may be rapidly executed in response to arequest to execute the code, without delay caused by initializing thevirtual machine instance. Thus, when an execution of a task istriggered, the code corresponding to that task can be executed within apre-initialized virtual machine in a very short amount of time.

A common programming technique in traditional environments is to allowasynchronous operations, such that two different operations (e.g., athread and a network-request, two threads, etc.) may occurasynchronously from one another. Generally, asynchronous operations aremanaged by the execution environment in which code executes (e.g., theoperating system, browser, virtual machine, etc., on which the codeexecutes). However, in an on-demand code execution system, handling ofasynchronous operations at the level of an execution environment can beinefficient. For example, asynchronous operations often result ininstances where one operation becomes “blocked,” waiting for anotheroperation. In such instances, an execution environment can take actionto reduce the computing resources dedicated to that operation (e.g., bysuspending the blocked thread until it becomes unblocked). In anon-demand code execution system, performing such actions at the level ofan execution environment can be inefficient, because the executionenvironment itself must generally remain in existence to detect when theoperation becomes unblocked. The result is that an environment continuesto utilize resources of the on-demand code execution system, potentiallyunnecessarily. Moreover, it is possible (and in some instances likely)that the state of the on-demand code execution system will changebetween a time at which an operation begins and a time that it becomes“unblocked.” Thus, while the on-demand code execution system may attemptto efficiently allocate computing resources to the initial execution ofa task, a different allocation may be more efficient at a time when thetask becomes unblocked. However, traditional suspension techniques,which occur within a localized execution environment, do not allow forefficient alteration of underlying computing resources when an operationbecomes unblocked.

Aspects of the present application address the above-noted issues byenabling asynchronous tasks to be efficiently suspended when blocked, atleast in part by suspending the execution environment in which the taskoperates. For example, when a task on the on-demand code executionsystem becomes blocked, the on-demand code execution system can savestate information regarding the task (such as a state of objects withinthe task), and suspend or deconstruct the execution environment in whichthe state has been operating. The on-demand code execution system canthen generate a notifier associated with the task's dependency (e.g.,the operation on which the task has become blocked) and, on completionof that dependency, regenerate an execution environment for the task onthe on-demand code execution system such that execution of the task cancontinue. In this manner, the computing resources associated withmaintaining an execution environment for a blocked task can be reducedor eliminated, increasing the efficiency of the on-demand code executionsystem.

Another characteristic of asynchronous operations is that, in someinstances, a dependency operation (an operation on which anotheroperation depends) may complete before such completion is actuallyrequired by a dependent operation (an operation that depends on anotheroperation). For example, a first operation (a dependent operation) mayasynchronously call a second operation (the dependency operation) and beprogrammed to continue performing other processes until the result ofthe second operation is needed. Under some conditions, the secondoperation may complete before a result is needed by the first operation.In traditional environments, this generally does not result in adverseeffect, since the result of the second operation can be stored untilneeded by the first operation. However, in an on-demand code executionsystem, many operations may be occurring simultaneously across a numberof execution environments, and the on-demand code execution system mayattempt to distribute those operations in an efficient manner, to reducethe overall computing resources needed by the on-demand code executionsystem at any given time. Moreover, many operations may betime-dependent, such that a result is needed very quickly (e.g., withinmilliseconds), and these operations can be negatively impacted byload-balancing efforts, such as queueing. Accordingly, completion ofoperations before a result is required can have a negative overallimpact on the system (e.g., because the computing resources required tocomplete the operation could have been used to complete other, moreurgent operations).

Aspects of the present application address this issue by enablingasynchronous tasks executing on the on-demand code execution system tobe associated with a “deadline,” indicating a predicted time at which aresult of the task will be required by a dependent task. When anasynchronous, dependency task is called, the on-demand code executionsystem can determine a deadline for the task, and enqueue the task forexecution by the deadline. For example, rather than executing thedependency task immediately, the on-demand code execution system maydelay execution until excess resources are available at the on-demandcode execution system, or until the deadline is reached. Thus, executionof asynchronous tasks at the on-demand code execution system can beordered to increase the efficiency at which the computing resources ofthe system are used.

The execution of tasks on the on-demand code execution system will nowbe discussed. Specifically, to execute tasks, the on-demand codeexecution system described herein may maintain a pool of pre-initializedvirtual machine instances that are ready for use as soon as a userrequest is received. Due to the pre-initialized nature of these virtualmachines, delay (sometimes referred to as latency) associated withexecuting the user code (e.g., instance and language runtime startuptime) can be significantly reduced, often to sub-100 millisecond levels.Illustratively, the on-demand code execution system may maintain a poolof virtual machine instances on one or more physical computing devices,where each virtual machine instance has one or more software components(e.g., operating systems, language runtimes, libraries, etc.) loadedthereon. When the on-demand code execution system receives a request toexecute the program code of a user (a “task”), which specifies one ormore computing constraints for executing the program code of the user,the on-demand code execution system may select a virtual machineinstance for executing the program code of the user based on the one ormore computing constraints specified by the request and cause theprogram code of the user to be executed on the selected virtual machineinstance. The program codes can be executed in isolated containers thatare created on the virtual machine instances. Since the virtual machineinstances in the pool have already been booted and loaded withparticular operating systems and language runtimes by the time therequests are received, the delay associated with finding computecapacity that can handle the requests (e.g., by executing the user codein one or more containers created on the virtual machine instances) issignificantly reduced.

The on-demand code execution system may include a virtual machineinstance manager configured to receive user code (threads, programs,etc., composed in any of a variety of programming languages) and executethe code in a highly scalable, low latency manner, without requiringuser configuration of a virtual machine instance. Specifically, thevirtual machine instance manager can, prior to receiving the user codeand prior to receiving any information from a user regarding anyparticular virtual machine instance configuration, create and configurevirtual machine instances according to a predetermined set ofconfigurations, each corresponding to any one or more of a variety ofrun-time environments. Thereafter, the virtual machine instance managerreceives user-initiated requests to execute code, and identifies apre-configured virtual machine instance to execute the code based onconfiguration information associated with the request. The virtualmachine instance manager can further allocate the identified virtualmachine instance to execute the user's code at least partly by creatingand configuring containers inside the allocated virtual machineinstance. Various embodiments for implementing a virtual machineinstance manager and executing user code on virtual machine instances isdescribed in more detail in U.S. Pat. No. 9,323,556, entitled“PROGRAMMATIC EVENT DETECTION AND MESSAGE GENERATION FOR REQUESTS TOEXECUTE PROGRAM CODE” and filed Sep. 30, 2014 (“the '556 Patent”), theentirety of which is hereby incorporated by reference.

As used herein, the term “virtual machine instance” is intended to referto an execution of software or other executable code that emulateshardware to provide an environment or platform on which software mayexecute (an “execution environment”). Virtual machine instances aregenerally executed by hardware devices, which may differ from thephysical hardware emulated by the virtual machine instance. For example,a virtual machine may emulate a first type of processor and memory whilebeing executed on a second type of processor and memory. Thus, virtualmachines can be utilized to execute software intended for a firstexecution environment (e.g., a first operating system) on a physicaldevice that is executing a second execution environment (e.g., a secondoperating system). In some instances, hardware emulated by a virtualmachine instance may be the same or similar to hardware of an underlyingdevice. For example, a device with a first type of processor mayimplement a plurality of virtual machine instances, each emulating aninstance of that first type of processor. Thus, virtual machineinstances can be used to divide a device into a number of logicalsub-devices (each referred to as a “virtual machine instance”). Whilevirtual machine instances can generally provide a level of abstractionaway from the hardware of an underlying physical device, thisabstraction is not required. For example, assume a device implements aplurality of virtual machine instances, each of which emulate hardwareidentical to that provided by the device. Under such a scenario, eachvirtual machine instance may allow a software application to executecode on the underlying hardware without translation, while maintaining alogical separation between software applications running on othervirtual machine instances. This process, which is generally referred toas “native execution,” may be utilized to increase the speed orperformance of virtual machine instances. Other techniques that allowdirect utilization of underlying hardware, such as hardware pass-throughtechniques, may be used, as well.

While a virtual machine executing an operating system is describedherein as one example of an execution environment, other executionenvironments are also possible. For example, tasks or other processesmay be executed within a software “container,” which provides a runtimeenvironment without itself providing virtualization of hardware.Containers may be implemented within virtual machines to provideadditional security, or may be run outside of a virtual machineinstance.

As will be appreciated by one skilled in the art, the embodimentsdescribed herein function to improve the functioning of computingdevices by enabling those devices to rapidly execute code of many userswithin an on-demand code execution system. Moreover, in the context ofan on-demand code execution system, the present disclosure enables theefficient execution of code within execution environments (e.g., virtualmachine instances, containers, etc.), while reducing inefficienciesassociated with asynchronous operations. Specifically, the presentdisclosure enables a reduction in the computing resources associatedwith blocked operations, by enabling an execution environment of thatblocked operation to be suspended, and enabling that environment to berecreated when the operation becomes unblocked. Further, the presentdisclosure enables efficient scheduling of asynchronous operations bythe use of deadlines associated with those operations. Thus, one skilledin the art will appreciate by virtue of the present disclosure that theembodiments described herein represent a substantial contribution to thetechnical field of virtual machine usage management, network-based codeexecution, and to computing devices in general.

The foregoing aspects and many of the attendant advantages of thisdisclosure will become more readily appreciated as the same becomebetter understood by reference to the following detailed description,when taken in conjunction with the accompanying drawings.

FIG. 1 is a block diagram of an illustrative operating environment 100in which an on-demand code execution system 110 may operate based oncommunication with user computing devices 102 and auxiliary services106. By way of illustration, various example user computing devices 102are shown in communication with the on-demand code execution system 110,including a desktop computer, laptop, and a mobile phone. In general,the user computing devices 102 can be any computing device such as adesktop, laptop or tablet computer, personal computer, wearablecomputer, server, personal digital assistant (PDA), hybrid PDA/mobilephone, mobile phone, electronic book reader, set-top box, voice commanddevice, camera, digital media player, and the like. The on-demand codeexecution system 110 may provide the user computing devices 102 with oneor more user interfaces, command-line interfaces (CLI), applicationprograming interfaces (API), and/or other programmatic interfaces forgenerating and uploading user-executable code, invoking theuser-provided code (e.g., submitting a request to execute the user codeson the on-demand code execution system 110), scheduling event-based jobsor timed jobs, tracking the user-provided code, and/or viewing otherlogging or monitoring information related to their requests and/or usercodes. Although one or more embodiments may be described herein as usinga user interface, it should be appreciated that such embodiments may,additionally or alternatively, use any CLIs, APIs, or other programmaticinterfaces.

The illustrative environment 100 further includes one or more auxiliaryservices 106, which can interact with the one-demand code executionenvironment 110 to implement desired functionality on behalf of a user.Auxiliary services 106 can correspond to network-connected computingdevices, such as servers, which generate data accessible to theone-demand code execution environment 110 or otherwise communicate tothe one-demand code execution environment 110. For example, theauxiliary services 106 can include web services (e.g., associated withthe user computing devices 102, with the on-demand code execution system110, or with third parties), data bases, really simple syndication(“RSS”) readers, social networking sites, or any other source ofnetwork-accessible service or data source. In some instances, auxiliaryservices 106 may be associated with the on-demand code execution system110, e.g., to provide billing or logging services to the on-demand codeexecution system 110. In some instances, auxiliary services 106 activelytransmit information, such as API calls or other task-triggeringinformation, to the on-demand code execution system 110. In otherinstances, auxiliary services 106 may be passive, such that data is madeavailable for access by the on-demand code execution system 110. Asdescribed below, components of the on-demand code execution system 110may periodically poll such passive data sources, and trigger executionof tasks within the on-demand code execution system 110 based on thedata provided. While depicted in FIG. 1 as distinct from the usercomputing devices 102 and the on-demand code execution system 110, insome embodiments, various auxiliary services 106 may be implemented byeither the user computing devices 102 or the on-demand code executionsystem 110.

The user computing devices 102 and auxiliary services 106 maycommunication with the on-demand code execution system 110 via network104, which may include any wired network, wireless network, orcombination thereof. For example, the network 104 may be a personal areanetwork, local area network, wide area network, over-the-air broadcastnetwork (e.g., for radio or television), cable network, satellitenetwork, cellular telephone network, or combination thereof. As afurther example, the network 104 may be a publicly accessible network oflinked networks, possibly operated by various distinct parties, such asthe Internet. In some embodiments, the network 104 may be a private orsemi-private network, such as a corporate or university intranet. Thenetwork 104 may include one or more wireless networks, such as a GlobalSystem for Mobile Communications (GSM) network, a Code Division MultipleAccess (CDMA) network, a Long Term Evolution (LTE) network, or any othertype of wireless network. The network 104 can use protocols andcomponents for communicating via the Internet or any of the otheraforementioned types of networks. For example, the protocols used by thenetwork 104 may include Hypertext Transfer Protocol (HTTP), HTTP Secure(HTTPS), Message Queue Telemetry Transport (MQTT), ConstrainedApplication Protocol (CoAP), and the like. Protocols and components forcommunicating via the Internet or any of the other aforementioned typesof communication networks are well known to those skilled in the artand, thus, are not described in more detail herein.

The on-demand code execution system 110 is depicted in FIG. 1 asoperating in a distributed computing environment including severalcomputer systems that are interconnected using one or more computernetworks (not shown in FIG. 1). The on-demand code execution system 110could also operate within a computing environment having a fewer orgreater number of devices than are illustrated in FIG. 1. Thus, thedepiction of the on-demand code execution system 110 in FIG. 1 should betaken as illustrative and not limiting to the present disclosure. Forexample, the on-demand code execution system 110 or various constituentsthereof could implement various Web services components, hosted or“cloud” computing environments, and/or peer to peer networkconfigurations to implement at least a portion of the processesdescribed herein.

Further, the on-demand code execution system 110 may be implementeddirectly in hardware or software executed by hardware devices and may,for instance, include one or more physical or virtual serversimplemented on physical computer hardware configured to execute computerexecutable instructions for performing various features that will bedescribed herein. The one or more servers may be geographicallydispersed or geographically co-located, for instance, in one or moredata centers. In some instances, the one or more servers may operate aspart of a system of rapidly provisioned and released computingresources, often referred to as a “cloud computing environment.”

In the example of FIG. 1, the on-demand code execution system 110 isillustrated as connected to the network 104. In some embodiments, any ofthe components within the on-demand code execution system 110 cancommunicate with other components of the on-demand code execution system110 via the network 104. In other embodiments, not all components of theon-demand code execution system 110 are capable of communicating withother components of the virtual environment 100. In one example, onlythe frontend 120 may be connected to the network 104, and othercomponents of the on-demand code execution system 110 may communicatewith other components of the virtual environment 100 via the frontend120.

In FIG. 1, users, by way of user computing devices 102, may interactwith the on-demand code execution system 110 to provide executable code,and establish rules or logic defining when and how such code should beexecuted on the on-demand code execution system 110, thus establishing a“task.” For example, a user may wish to run a piece of code inconnection with a web or mobile application that the user has developed.One way of running the code would be to acquire virtual machineinstances from service providers who provide infrastructure as aservice, configure the virtual machine instances to suit the user'sneeds, and use the configured virtual machine instances to run the code.In order to avoid the complexity of this process, the user mayalternatively provide the code to the on-demand code execution system110, and request that the on-demand code execution system 110 executethe code using one or more pre-established virtual machine instances.The on-demand code execution system 110 can handle the acquisition andconfiguration of compute capacity (e.g., containers, instances, etc.,which are described in greater detail below) based on the code executionrequest, and execute the code using the compute capacity. The on-demandcode execution system 110 may automatically scale up and down based onthe volume, thereby relieving the user from the burden of having toworry about over-utilization (e.g., acquiring too little computingresources and suffering performance issues) or under-utilization (e.g.,acquiring more computing resources than necessary to run the codes, andthus overpaying).

To enable interaction with the on-demand code execution system 110, theenvironment 110 includes a frontend 120, which enables interaction withthe on-demand code execution system 110. In an illustrative embodiment,the frontend 120 serves as a “front door” to the other services providedby the on-demand code execution system 110, enabling users (via usercomputing devices 102) to provide, request execution of, and viewresults of computer executable code. The frontend 120 includes a varietyof components (not shown in FIG. 1) to enable interaction between theon-demand code execution system 110 and other computing devices. Forexample, the frontend 120 can includes a request interface providinguser computing devices 102 with the ability to upload or otherwisecommunication user-specified code to the on-demand code execution system110 and to thereafter request execution of that code. In one embodiment,the request interfaces communicates with external computing devices(e.g., user computing devices 102, auxiliary services 106, etc.) via agraphical user interface (GUI), CLI, or API. The frontend 120 processesthe requests and makes sure that the requests are properly authorized.For example, the frontend 120 may determine whether the user associatedwith the request is authorized to access the user code specified in therequest.

The user code as used herein may refer to any program code (e.g., aprogram, routine, subroutine, thread, etc.) written in a specificprogram language. In the present disclosure, the terms “code,” “usercode,” and “program code,” may be used interchangeably. Such user codemay be executed to achieve a specific function, for example, inconnection with a particular web application or mobile applicationdeveloped by the user. As noted above, individual collections of usercode (e.g., to achieve a specific function) are referred to herein as“tasks,” while specific executions of that code are referred to as “taskexecutions” or simply “executions.” Tasks may be written, by way ofnon-limiting example, in JavaScript (e.g., node.js), Java, Python,and/or Ruby (and/or another programming language). Tasks may be“triggered” for execution on the on-demand code execution system 110 ina variety of manners. In one embodiment, a user or other computingdevice may transmit a request to execute a task may, which can generallybe referred to as “call” to execute of the task. Such calls may includethe user code (or the location thereof) to be executed and one or morearguments to be used for executing the user code. For example, a callmay provide the user code of a task along with the request to executethe task. In another example, a call may identify a previously uploadedtask by its name or an identifier. In yet another example, codecorresponding to a task may be included in a call for the task, as wellas being uploaded in a separate location (e.g., storage of an auxiliaryservice 106 or a storage system internal to the on-demand code executionsystem 110) prior to the request being received by the on-demand codeexecution system 110. The on-demand code execution system 110 may varyits execution strategy for a task based on where the code of the task isavailable at the time a call for the task is processed.

A request interface of the frontend 120 may receive calls to executetasks as Hypertext Transfer Protocol Secure (HTTPS) requests from auser. Also, any information (e.g., headers and parameters) included inthe HTTPS request may also be processed and utilized when executing atask. As discussed above, any other protocols, including, for example,HTTP, MQTT, and CoAP, may be used to transfer the message containing atask call to the request interface 122.

A call to execute a task may specify one or more third-party libraries(including native libraries) to be used along with the user codecorresponding to the task. In one embodiment, the call may provide tothe on-demand code execution system 110 a ZIP file containing the usercode and any libraries (and/or identifications of storage locationsthereof) corresponding to the task requested for execution. In someembodiments, the call includes metadata that indicates the program codeof the task to be executed, the language in which the program code iswritten, the user associated with the call, and/or the computingresources (e.g., memory, etc.) to be reserved for executing the programcode. For example, the program code of a task may be provided with thecall, previously uploaded by the user, provided by the on-demand codeexecution system 110 (e.g., standard routines), and/or provided by thirdparties. In some embodiments, such resource-level constraints (e.g., howmuch memory is to be allocated for executing a particular user code) arespecified for the particular task, and may not vary over each executionof the task. In such cases, the on-demand code execution system 110 mayhave access to such resource-level constraints before each individualcall is received, and the individual call may not specify suchresource-level constraints. In some embodiments, the call may specifyother constraints such as permission data that indicates what kind ofpermissions or authorities that the call invokes to execute the task.Such permission data may be used by the on-demand code execution system110 to access private resources (e.g., on a private network).

In some embodiments, a call may specify the behavior that should beadopted for handling the call. In such embodiments, the call may includean indicator for enabling one or more execution modes in which toexecute the task referenced in the call. For example, the call mayinclude a flag or a header for indicating whether the task should beexecuted in a debug mode in which the debugging and/or logging outputthat may be generated in connection with the execution of the task isprovided back to the user (e.g., via a console user interface). In suchan example, the on-demand code execution system 110 may inspect the calland look for the flag or the header, and if it is present, the on-demandcode execution system 110 may modify the behavior (e.g., loggingfacilities) of the container in which the task is executed, and causethe output data to be provided back to the user. In some embodiments,the behavior/mode indicators are added to the call by the user interfaceprovided to the user by the on-demand code execution system 110. Otherfeatures such as source code profiling, remote debugging, etc. may alsobe enabled or disabled based on the indication provided in a call.

To manage requests for code execution, the frontend 120 can furtherinclude an execution queue (not shown in FIG. 1), which can maintain arecord of user-requested task executions. Illustratively, the number ofsimultaneous task executions by the on-demand code execution system 110is limited, and as such, new task executions initiated at the on-demandcode execution system 110 (e.g., via an API call) may be placed on theexecution queue and processed, e.g., in a first-in-first-out order. Insome embodiments, the on-demand code execution system 110 may includemultiple execution queues, such as individual execution queues for eachuser account. For example, users of the on-demand code execution system110 may desire to limit the rate of task executions on the on-demandcode execution system 110 (e.g., for cost reasons). Thus, the on-demandcode execution system 110 may utilize an account-specific executionqueue to throttle the rate of simultaneous task executions by a specificuser account. In some instances, the on-demand code execution system 110may prioritize task executions, such that task executions of specificaccounts or of specified priorities bypass or are prioritized within theexecution queue. The number and configuration of execution queues may insome instances be modified based on pre-trigger notifications receivedat the on-demand code execution system 110 (e.g., based on a predictednumber of subsequent task calls to be received based on the pre-triggernotifications). In other instances, the on-demand code execution system110 may execute tasks immediately or substantially immediately afterreceiving a call for that task, and thus, the execution queue may beomitted.

As noted above, tasks may be triggered for execution at the on-demandcode execution system 110 based on explicit calls from user computingdevices 102 (e.g., as received at the request interface 120).Alternatively or additionally, tasks may be triggered for execution atthe on-demand code execution system 110 based on data retrieved from oneor more auxiliary services 106. To facilitate interaction with auxiliaryservices 106, the frontend 120 can include a polling interface (notshown in FIG. 1), which operates to poll auxiliary services 106 fordata. Illustratively, the polling interface may periodically transmit arequest to one or more user-specified auxiliary services 106 to retrieveany newly available data (e.g., social network “posts,” news articles,etc.), and to determine whether that data corresponds to auser-established criteria triggering execution a task on the on-demandcode execution system 110. Illustratively, criteria for execution of atask may include, but is not limited to, whether new data is availableat the auxiliary services 106, the type or content of the data, ortiming information corresponding to the data. In addition to tasksexecuted based on explicit user calls and data from auxiliary services106, the on-demand code execution system 110 may in some instancesoperate to trigger execution of tasks independently. For example, theon-demand code execution system 110 may operate (based on instructionsfrom a user) to trigger execution of a task at each of a number ofspecified time intervals (e.g., every 10 minutes).

The frontend 120 can further includes an output interface (not shown inFIG. 1) configured to output information regarding the execution oftasks on the on-demand code execution system 110. Illustratively, theoutput interface may transmit data regarding task executions (e.g.,results of a task, errors related to the task execution, or details ofthe task execution, such as total time required to complete theexecution, total data processed via the execution, etc.) or pre-triggernotifications (received pre-trigger notifications, actions taken basedon pre-trigger notification, determined correlations between pre-triggernotifications and subsequent task executions, etc.) to the usercomputing devices 102 or to auxiliary services 106, which may include,for example, billing or logging services. The output interface mayfurther enable transmission of data, such as service calls, to auxiliaryservices 106. For example, the output interface may be utilized duringexecution of a task to transmit an API request to an external service106 (e.g., to store data generated during execution of the task).

While not shown in FIG. 1, in some embodiments, the on-demand codeexecution system 110 may include multiple frontends 120. In suchembodiments, a load balancer may be provided to distribute the incomingcalls to the multiple frontends 120, for example, in a round-robinfashion. In some embodiments, the manner in which the load balancerdistributes incoming calls to the multiple frontends 120 may be based onthe state of the warming pool 130A and/or the active pool 140A. Forexample, if the capacity in the warming pool 130A is deemed to besufficient, the calls may be distributed to the multiple frontends 120based on the individual capacities of the frontends 120 (e.g., based onone or more load balancing restrictions). On the other hand, if thecapacity in the warming pool 130A is less than a threshold amount, oneor more of such load balancing restrictions may be removed such that thecalls may be distributed to the multiple frontends 120 in a manner thatreduces or minimizes the number of virtual machine instances taken fromthe warming pool 130A. For example, even if, according to a loadbalancing restriction, a call is to be routed to Frontend A, if FrontendA needs to take an instance out of the warming pool 130A to service thecall but Frontend B can use one of the instances in its active pool toservice the same call, the call may be routed to Frontend B.

To execute tasks, the on-demand code execution system 110 includes awarming pool manager 130, which “pre-warms” (e.g., initializes) virtualmachine instances to enable tasks to be executed quickly, without thedelay caused by initialization of the virtual machines. The on-demandcode execution system 110 further includes a worker manager 140, whichmanages active virtual machine instances (e.g., currently assigned toexecute tasks in response to task calls).

The warming pool manager 130 ensures that virtual machine instances areready to be used by the worker manager 140 when the on-demand codeexecution system 110 detects an event triggering execution of a task onthe on-demand code execution system 110. In the example illustrated inFIG. 1, the warming pool manager 130 manages the warming pool 130A,which is a group (sometimes referred to as a pool) of pre-initializedand pre-configured virtual machine instances that may be used to executetasks in response to triggering of those tasks. In some embodiments, thewarming pool manager 130 causes virtual machine instances to be bootedup on one or more physical computing machines within the on-demand codeexecution system 110 and added to the warming pool 130A. For example,the warming pool manager 130 may cause additional instances to be addedto the warming pool 130A based on the available capacity in the warmingpool 130A to service incoming calls. As will be described below, thewarming pool manager 130 may further work in conjunction with othercomponents of the on-demand code execution system 110, such as theworker manager 140, to add or otherwise manage instances and/orcontainers in the warming pool based on received pre-triggernotifications. In some embodiments, the warming pool manager 130 mayutilize both physical computing devices within the on-demand codeexecution system 110 and one or more virtual machine instance servicesto acquire and maintain compute capacity that can be used to servicecalls received by the frontend 120. Further, the on-demand codeexecution system 110 may comprise one or more logical knobs or switchesfor controlling (e.g., increasing or decreasing) the available capacityin the warming pool 130A. For example, a system administrator may usesuch a knob or switch to increase the capacity available (e.g., thenumber of pre-booted instances) in the warming pool 130A during peakhours. In some embodiments, virtual machine instances in the warmingpool 130A can be configured based on a predetermined set ofconfigurations independent from a specific call to execute a task. Thepredetermined set of configurations can correspond to various types ofvirtual machine instances to execute tasks. The warming pool manager 130can optimize types and numbers of virtual machine instances in thewarming pool 130A based on one or more metrics related to current orprevious task executions. Further, the warming pool manager 130 canestablish or modify the types and number of virtual machine instances inthe warming pool 130A based on pre-trigger notifications (e.g., bypre-initializing one or more virtual machine instances based onrequirements of a task expected to be executed based on a receivedpre-trigger notification).

As shown in FIG. 1, instances may have operating systems (OS) and/orlanguage runtimes loaded thereon. For example, the warming pool 130Amanaged by the warming pool manager 130 comprises instances 152, 154.The instance 152 includes an OS 152A and a runtime 152B. The instance154 includes an OS 154A. In some embodiments, the instances in thewarming pool 130A may also include containers (which may further containcopies of operating systems, runtimes, user codes, etc.), which aredescribed in greater detail below. Although the instance 152 is shown inFIG. 1 to include a single runtime, in other embodiments, the instancesdepicted in FIG. 1 may include two or more runtimes, each of which maybe used for running a different user code. In some embodiments, thewarming pool manager 130 may maintain a list of instances in the warmingpool 130A. The list of instances may further specify the configuration(e.g., OS, runtime, container, etc.) of the instances.

In some embodiments, the virtual machine instances in the warming pool130A may be used to serve any user's calls. In one embodiment, all thevirtual machine instances in the warming pool 130A are configured in thesame or substantially similar manner. In another embodiment, the virtualmachine instances in the warming pool 130A may be configured differentlyto suit the needs of different users. For example, the virtual machineinstances may have different operating systems, different languageruntimes, and/or different libraries loaded thereon. In yet anotherembodiment, the virtual machine instances in the warming pool 130A maybe configured in the same or substantially similar manner (e.g., withthe same OS, language runtimes, and/or libraries), but some of thoseinstances may have different container configurations. For example, oneinstance might have a container created therein for running code writtenin Python, and another instance might have a container created thereinfor running code written in Ruby. In some embodiments, multiple warmingpools 130A, each having identically-configured virtual machineinstances, are provided.

The warming pool manager 130 may pre-configure the virtual machineinstances in the warming pool 130A, such that each virtual machineinstance is configured to satisfy at least one of the operatingconditions that may be requested or specified by a user when defining atask. In one embodiment, the operating conditions may include programlanguages in which the potential user code of a task may be written. Forexample, such languages may include Java, JavaScript, Python, Ruby, andthe like. In some embodiments, the set of languages that the user codeof a task may be written in may be limited to a predetermined set (e.g.,set of 4 languages, although in some embodiments sets of more or lessthan four languages are provided) in order to facilitatepre-initialization of the virtual machine instances that can satisfycalls to execute the task. For example, when the user is configuring atask via a user interface provided by the on-demand code executionsystem 110, the user interface may prompt the user to specify one of thepredetermined operating conditions for executing the task. In anotherexample, the service-level agreement (SLA) for utilizing the servicesprovided by the on-demand code execution system 110 may specify a set ofconditions (e.g., programming languages, computing resources, etc.) thattasks should satisfy, and the on-demand code execution system 110 mayassume that the tasks satisfy the set of conditions in handling therequests. In another example, operating conditions specified by a taskmay include: the amount of compute power to be used for executing thetask; the type of triggering event for a task (e.g., an API call, HTTPpacket transmission, detection of a specific data at an auxiliaryservice 106); the timeout for the task (e.g., threshold time after whichan execution of the task may be terminated); and security policies(e.g., may control which instances in the warming pool 130A are usableby which user), among other specified conditions.

The worker manager 140 manages the instances used for servicing incomingcalls to execute tasks. In the example illustrated in FIG. 1, the workermanager 140 manages the active pool 140A, which is a group (sometimesreferred to as a pool) of virtual machine instances, implemented by oneor more physical host computing devices, that are currently assigned toone or more users. Although the virtual machine instances are describedhere as being assigned to a particular user, in some embodiments, theinstances may be assigned to a group of users, such that the instance istied to the group of users and any member of the group can utilizeresources on the instance. For example, the users in the same group maybelong to the same security group (e.g., based on their securitycredentials) such that executing one member's task in a container on aparticular instance after another member's task has been executed inanother container on the same instance does not pose security risks.Similarly, the worker manager 140 may assign the instances and thecontainers according to one or more policies that dictate which requestscan be executed in which containers and which instances can be assignedto which users. An example policy may specify that instances areassigned to collections of users who share the same account (e.g.,account for accessing the services provided by the on-demand codeexecution system 110). In some embodiments, the requests associated withthe same user group may share the same containers (e.g., if the usercodes associated therewith are identical). In some embodiments, a taskdoes not differentiate between the different users of the group andsimply indicates the group to which the users associated with the taskbelong.

As shown in FIG. 1, instances may have operating systems (OS), languageruntimes, and containers. The containers may have individual copies ofthe OS, the runtimes, and user codes corresponding to various tasksloaded thereon. In the example of FIG. 1, the active pool 140A managedby the worker manager 140 includes the instances 156, 158. The instance156 has an OS 156A, runtimes 156B, 156C, and containers 156D, 156E. Thecontainer 156D includes a copy of the OS 156A, a copy of the runtime156B, and a copy of a code 156D-1. The container 156E includes a copy ofthe OS 156A, a copy of the runtime 156C, and a copy of a code 156E-1.The instance 158 has an OS 158A, runtimes 158B, 158C, 158E, 158F, acontainer 158D, and codes 158G, 158H. The container 158D has a copy ofthe OS 158A, a copy of the runtime 158B, and a copy of a code 158D-1. Asillustrated in FIG. 1, instances may have user codes loaded thereon, andcontainers within those instances may also have user codes loadedtherein. In some embodiments, the worker manager 140 may maintain a listof instances in the active pool 140A. The list of instances may furtherspecify the configuration (e.g., OS, runtime, container, etc.) of theinstances. In some embodiments, the worker manager 140 may have accessto a list of instances in the warming pool 130A (e.g., including thenumber and type of instances). In other embodiments, the worker manager140 requests compute capacity from the warming pool manager 130 withouthaving knowledge of the virtual machine instances in the warming pool130A.

In the example illustrated in FIG. 1, tasks are executed in isolatedon-demand code execution systems referred to as containers (e.g.,containers 156D, 156E, 158D). Containers are logical units createdwithin a virtual machine instance using the resources available on thatinstance. For example, the worker manager 140 may, based on informationspecified in a call to execute a task, create a new container or locatean existing container in one of the instances in the active pool 140Aand assigns the container to the call to handle the execution of thetask. In one embodiment, such containers are implemented as Linuxcontainers.

Once a triggering event to execute a task has been successfullyprocessed by the frontend 120, the worker manager 140 finds capacity toexecute a task on the on-demand code execution system 110. For example,if there exists a particular virtual machine instance in the active pool140A that has a container with the user code of the task already loadedtherein (e.g., code 156D-1 shown in the container 156D), the workermanager 140 may assign the container to the task and cause the task tobe executed in the container. Alternatively, if the user code of thetask is available in the local cache of one of the virtual machineinstances (e.g., codes 158G, 158H, which are stored on the instance 158but do not belong to any individual containers), the worker manager 140may create a new container on such an instance, assign the container tothe task, and cause the user code of the task to be loaded and executedin the container.

If the worker manager 140 determines that the user code associated withthe triggered task is not found on any of the instances (e.g., either ina container or the local cache of an instance) in the active pool 140A,the worker manager 140 may determine whether any of the instances in theactive pool 140A is currently assigned to the user associated with thetriggered task and has compute capacity to handle the triggered task. Ifthere is such an instance, the worker manager 140 may create a newcontainer on the instance and assign the container to execute thetriggered task. Alternatively, the worker manager 140 may furtherconfigure an existing container on the instance assigned to the user,and assign the container to the triggered task. For example, the workermanager 140 may determine that the existing container may be used toexecute the task if a particular library demanded by the task is loadedthereon. In such a case, the worker manager 140 may load the particularlibrary and the code of the task onto the container and use thecontainer to execute the task.

If the active pool 140 does not contain any instances currently assignedto the user, the worker manager 140 pulls a new virtual machine instancefrom the warming pool 130A, assigns the instance to the user associatedwith the triggered task, creates a new container on the instance,assigns the container to the triggered task, and causes the user code ofthe task to be downloaded and executed on the container.

In some embodiments, the on-demand code execution system 110 is adaptedto begin execution of a task shortly after it is received (e.g., by thefrontend 120). A time period can be determined as the difference in timebetween initiating execution of the task (e.g., in a container on avirtual machine instance associated with the user) and detecting anevent that triggers execution of the task (e.g., a call received by thefrontend 120). The on-demand code execution system 110 is adapted tobegin execution of a task within a time period that is less than apredetermined duration. In one embodiment, the predetermined duration is500 ms. In another embodiment, the predetermined duration is 300 ms. Inanother embodiment, the predetermined duration is 100 ms. In anotherembodiment, the predetermined duration is 50 ms. In another embodiment,the predetermined duration is 10 ms. In another embodiment, thepredetermined duration may be any value chosen from the range of 10 msto 500 ms. In some embodiments, the on-demand code execution system 110is adapted to begin execution of a task within a time period that isless than a predetermined duration if one or more conditions aresatisfied. For example, the one or more conditions may include any oneof: (1) the user code of the task is loaded on a container in the activepool 140 at the time the request is received; (2) the user code of thetask is stored in the code cache of an instance in the active pool 140at the time the call to the task is received; (3) the active pool 140Acontains an instance assigned to the user associated with the call atthe time the call is received; or (4) the warming pool 130A has capacityto handle the task at the time the event triggering execution of thetask is detected.

Once the worker manager 140 locates one of the virtual machine instancesin the warming pool 130A that can be used to execute a task, the warmingpool manager 130 or the worker manger 140 takes the instance out of thewarming pool 130A and assigns it to the user associated with therequest. The assigned virtual machine instance is taken out of thewarming pool 130A and placed in the active pool 140A. In someembodiments, once the virtual machine instance has been assigned to aparticular user, the same virtual machine instance cannot be used toexecute tasks of any other user. This provides security benefits tousers by preventing possible co-mingling of user resources.Alternatively, in some embodiments, multiple containers belonging todifferent users (or assigned to requests associated with differentusers) may co-exist on a single virtual machine instance. Such anapproach may improve utilization of the available compute capacity.

In some embodiments, the on-demand code execution system 110 maymaintain a separate cache in which code of tasks are stored to serve asan intermediate level of caching system between the local cache of thevirtual machine instances and the account data store 164 (or othernetwork-based storage not shown in FIG. 1). The various scenarios thatthe worker manager 140 may encounter in servicing the call are describedin greater detail within the '556 Patent, incorporated by referenceabove (e.g., at FIG. 4 of the '556 Patent).

After the task has been executed, the worker manager 140 may tear downthe container used to execute the task to free up the resources itoccupied to be used for other containers in the instance. Alternatively,the worker manager 140 may keep the container running to use it toservice additional calls from the same user. For example, if anothercall associated with the same task that has already been loaded in thecontainer, the call can be assigned to the same container, therebyeliminating the delay associated with creating a new container andloading the code of the task in the container. In some embodiments, theworker manager 140 may tear down the instance in which the containerused to execute the task was created. Alternatively, the worker manager140 may keep the instance running to use it to service additional callsfrom the same user. The determination of whether to keep the containerand/or the instance running after the task is done executing may bebased on a threshold time, the type of the user, average task executionvolume of the user, and/or other operating conditions. For example,after a threshold time has passed (e.g., 5 minutes, 30 minutes, 1 hour,24 hours, 30 days, etc.) without any activity (e.g., task execution),the container and/or the virtual machine instance is shutdown (e.g.,deleted, terminated, etc.), and resources allocated thereto arereleased. In some embodiments, the threshold time passed before acontainer is torn down is shorter than the threshold time passed beforean instance is torn down.

In some embodiments, the on-demand code execution system 110 may providedata to one or more of the auxiliary services 106 as it executes tasksin response to triggering events. For example, the frontend 120 maycommunicate with the monitoring/logging/billing services included withinthe auxiliary services 106. The monitoring/logging/billing services mayinclude: a monitoring service for managing monitoring informationreceived from the on-demand code execution system 110, such as statusesof containers and instances on the on-demand code execution system 110;a logging service for managing logging information received from theon-demand code execution system 110, such as activities performed bycontainers and instances on the on-demand code execution system 110; anda billing service for generating billing information associated withexecuting user code on the on-demand code execution system 110 (e.g.,based on the monitoring information and/or the logging informationmanaged by the monitoring service and the logging service). In additionto the system-level activities that may be performed by themonitoring/logging/billing services (e.g., on behalf of the on-demandcode execution system 110), the monitoring/logging/billing services mayprovide application-level services on behalf of the tasks executed onthe on-demand code execution system 110. For example, themonitoring/logging/billing services may monitor and/or log variousinputs, outputs, or other data and parameters on behalf of the tasksbeing executed on the on-demand code execution system 110. As will bedescribed in more detail below, the frontend 120 may additionallyinteract with auxiliary services 106 to receive pre-triggernotifications indicating a potential for subsequent calls to executetasks on the on-demand code execution system 110.

In some embodiments, the worker manager 140 may perform health checks onthe instances and containers managed by the worker manager 140 (e.g.,those in the active pool 140A). For example, the health checks performedby the worker manager 140 may include determining whether the instancesand the containers managed by the worker manager 140 have any issues of(1) misconfigured networking and/or startup configuration, (2) exhaustedmemory, (3) corrupted file system, (4) incompatible kernel, and/or anyother problems that may impair the performance of the instances and thecontainers. In one embodiment, the worker manager 140 performs thehealth checks periodically (e.g., every 5 minutes, every 30 minutes,every hour, every 24 hours, etc.). In some embodiments, the frequency ofthe health checks may be adjusted automatically based on the result ofthe health checks. In other embodiments, the frequency of the healthchecks may be adjusted based on user requests. In some embodiments, theworker manager 140 may perform similar health checks on the instancesand/or containers in the warming pool 130A. The instances and/or thecontainers in the warming pool 130A may be managed either together withthose instances and containers in the active pool 140A or separately. Insome embodiments, in the case where the health of the instances and/orthe containers in the warming pool 130A is managed separately from theactive pool 140A, the warming pool manager 130, instead of the workermanager 140, may perform the health checks described above on theinstances and/or the containers in the warming pool 130A.

The worker manager 140 may include an instance allocation unit forfinding compute capacity (e.g., containers) to service incoming codeexecution requests and a user code execution unit for facilitating theexecution of user codes on those containers. An example configuration ofthe worker manager 140 is described in greater detail within the '556Patent, incorporated by reference above (e.g., within FIG. 2 of the '556Patent). In some instance, the instance allocation unit's operation maybe modified based on expected incoming code execution requests, aspredicted based on received pre-trigger notifications. For example,where the on-demand code execution system 110 utilizes or has access todynamically provisioned computing resources (such as dynamicallyprovisioned network-based storage space, scalable access to processingpower, etc.), the instance allocation unit may be configured to modifyan amount of one or more of those dynamically provisioned computingresources. For example, the instance allocation unit may interact with adynamically allocated network storage service (not shown in FIG. 1) toincrease the amount of data storage available to virtual machineinstances.

In the depicted example, virtual machine instances (“instances”) 152,154 are shown in a warming pool 130A managed by the warming pool manager130, and instances 156, 158 are shown in an active pool 140A managed bythe worker manager 140. The illustration of the various componentswithin the on-demand code execution system 110 is logical in nature andone or more of the components can be implemented by a single computingdevice or multiple computing devices. For example, the instances 152,154, 156, 158 can be implemented on one or more physical computingdevices in different various geographic regions. Similarly, each of thefrontend 120, the warming pool manager 130, and the worker manager 140can be implemented across multiple physical computing devices.Alternatively, one or more of the frontend 120, the warming pool manager130, and the worker manager 140 can be implemented on a single physicalcomputing device. In some embodiments, the on-demand code executionsystem 110 may comprise multiple frontends 120, multiple warming poolmanagers 130, and/or multiple worker managers 140. Although four virtualmachine instances are shown in the example of FIG. 1, the embodimentsdescribed herein are not limited as such, and one skilled in the artwill appreciate that the on-demand code execution system 110 maycomprise any number of virtual machine instances implemented using anynumber of physical computing devices. Similarly, although a singlewarming pool 130A and a single active pool 140A are shown in the exampleof FIG. 1, the embodiments described herein are not limited as such, andone skilled in the art will appreciate that the on-demand code executionsystem 110 may comprise any number of warming pools and active pools.

While not shown in FIG. 1, in some embodiments, the on-demand codeexecution system 110 may include multiple warming pool managers 130and/or multiple worker managers 140, each operating distinct warmingpools 130A and active pools 140A. For example, a variety of warmingpools 130A and active pools 140A may be established at differentgeographic locations, each with a corresponding warming pool manager 130and worker manager 140. The frontend 120 may distribute tasks amongdifferent active pools 140A according to a variety of criteria, such asload balancing of the pools, a location of the resources required by thetask, or the suitability of virtual machines instances in the pools toexecute the task.

In accordance with embodiments of the present disclosure, the on-demandcode execution system 110 further includes an async controller 160,which includes components for managing asynchronous operations on theon-demand code execution system 110. As used herein, asynchronousoperations can refer to any combination of operation types, includingfor example two tasks on the on-demand code execution system 160, or afirst task on the on-demand code execution system 160 and a second,non-task operation (e.g., an HTTP request, an API call to an externalservice). In order to efficiently execute tasks that utilizeasynchronous operation, the async controller 160 can include an asyncscheduler 162, which interacts with components of the on-demand codeexecution system 110 to enable tasks that have become “blocked” waitingon an operation to be removed from an execution environment (potentiallyresulting in suspension or deconstruction of the execution environment),to reduce the computing resources associated with the task. To enablethe task to resume once a dependency operation has completed, the asyncscheduler 162 can store state information of the task within a statedata store 166. The async scheduler 162 can further store informationabout the dependencies of the task within a dependency data store 168,such that the task can be resumed when the dependencies have beenfulfilled. For example, the async controller 162 can operate to receivenotifications for when a dependency operation has completed, andinteract with other components of the on-demand code execution system110 to resume the task, by using the information from the state datastore 166 to place the task in a new execution environment with the samestate it had prior to being removed from its initial executionenvironment, or by recreating the prior execution environment. Moreover,the async scheduler 162 can operate to efficiently order the executionof dependencies, in instances where those dependencies are not requiredto execute immediately. Specifically, the async scheduler 162 can benotified of a dependency operation, as well as a deadline at whichcompletion of the dependency operation is expected to complete, andinteract with other components of the on-demand code execution system110 to schedule execution of the dependency operation at an efficienttime prior to the deadline (e.g., a time in which the on-demand codeexecution environment 110 has excess capacity). For ease of description,an asynchronous dependency operation, and particularly those that arenot required to execute immediately, are sometimes referred to herein as“promises” (e.g., representing a figurative “promise” that the operationwill complete in the future, when needed). Also for ease of description,the results of asynchronous dependency operations (“promises”) maysometimes be referred to herein as “futures” (e.g., representing a valuethat is not initially available, but is expected to become available inthe future). Information regarding promises and futures may be storedwithin a promises data store 164. Each of the promises data store 164,the state data store 166, and the dependency data store 168 maycorrespond to any persistent or substantially persistent data storage,such as a hard drive (HDD), a solid state drive (SDD), network attachedstorage (NAS), a tape drive, or any combination thereof. While shown asmultiple data stores, any of the promises data store 164, the state datastore 166, and the dependency data store 168 may be implemented oncommon underlying data storage devices.

FIG. 2 depicts a general architecture of a computing system (referencedas server 200) that implements embodiments of the present disclosure toenable handling of asynchronous task executions on the on-demand codeexecution system 110. The general architecture of the server 200depicted in FIG. 2 includes an arrangement of computer hardware andsoftware modules that may be used to implement aspects of the presentdisclosure. The hardware modules may be implemented with physicalelectronic devices, as discussed in greater detail below. The server 200may include many more (or fewer) elements than those shown in FIG. 2. Itis not necessary, however, that all of these generally conventionalelements be shown in order to provide an enabling disclosure.Additionally, the general architecture illustrated in FIG. 2 may be usedto implement one or more of the other components illustrated in FIG. 1.As illustrated, the server 200 includes a processing unit 210, a networkinterface 212, a computer readable medium drive 214, and an input/outputdevice interface 216, all of which may communicate with one another byway of a communication bus. The network interface 212 may provideconnectivity to one or more networks or computing systems. Theprocessing unit 210 may thus receive information and instructions fromother computing systems or services via the network 104. The processingunit 210 may also communicate to and from memory 220 and further provideoutput information for an optional display (not shown) via theinput/output device interface 216. The input/output device interface 216may also accept input from an optional input device (not shown).

The memory 220 may contain computer program instructions (grouped asmodules in some embodiments) that the processing unit 210 executes inorder to implement one or more aspects of the present disclosure. Thememory 210 generally includes RAM, ROM and/or other persistent,auxiliary or non-transitory computer readable media. The memory 210 maystore an operating system 224 that provides computer programinstructions for use by the processing unit 210 in the generaladministration and operation of the server 200. The memory 220 mayfurther include computer program instructions and other information forimplementing aspects of the present disclosure. For example, in oneembodiment, the memory 220 includes a user interface unit 222 thatgenerates user interfaces (and/or instructions therefor) for displayupon a computing device, e.g., via a navigation and/or browsinginterface such as a browser or application installed on the computingdevice. In addition, the memory 220 may include and/or communicate withone or more data repositories, such as the data store 202, which maycorrespond to any persistent or substantially persistent data storage,such as a hard drive (HDD), a solid state drive (SDD), network attachedstorage (NAS), a tape drive, or any combination thereof.

In addition to and/or in combination with the user interface unit 222,the memory 220 may include async controller software 226 thatcorresponds to computer-executable instructions which, when executed bythe server 200, implement the functions described above with respect tothe async controller 160. While async controller software 226 is shownin FIG. 2 as part of the server 200, in other embodiments, all or aportion of the async controller 160 may be implemented by othercomponents of the on-demand code execution system 110 and/or anothercomputing device. For example, in certain embodiments of the presentdisclosure, another computing device in communication with the on-demandcode execution system 110 may include several modules or components thatoperate similarly to the modules and components illustrated as part ofthe account manager 160.

While the computing device of FIG. 2 is described as implementing theasync controller 160, the same or a similar computing device mayadditionally or alternatively be utilized to implement other componentsof the on-demand code execution system 110. For example, such acomputing device may be utilized, independently or in conjunction withother components (e.g., data stores) to implement the warming poolmanager 130 or worker manager 140 of FIG. 1. The software orcomputer-executable instructions placed within the memory 220 may bemodified to enable execution of the functions described herein withrespect to the warming pool manager 130 or worker manager 140.

With reference to FIGS. 3A and 3B, illustrative interactions aredepicted for efficiently handling blocked task executions on theon-demand code execution system 110, by removing the task from anexecution environment within the active pool 140A while the task isblocked, and resuming the task within the same or a different executionenvironment when the task is unblocked. Specifically, FIG. 3A depictsinteractions for detecting that a task is blocked, for saving the stateof a task during blocking, and for removing the task from an executionenvironment. FIG. 3B depicts interactions for detecting that thedependency of the task has completed, and for resuming execution of thetask in a new or recreated execution environment. While shown in twofigures, the numbering of interactions in FIGS. 3A and 3B is maintainedfor clarity.

The interactions of FIG. 3A begin at (1), where a user device 102submits to the frontend 120 a call to a task on the on-demand codeexecution system. As noted above, submission of a call may includetransmission of specialized data to the frontend 120, such as a HTTPpacket or API call referencing the task alias. While the interactions ofFIG. 3A are described as including an explicit call to the task by theuser device 102, calls to the task may occur in a variety of manners,including submission of a call by auxiliary services 106 (not shown inFIG. 3A) or generation of a call by the on-demand code execution system110 (e.g., based on a rule to call the alias when specific criteria aremet, such as elapsing of a period of time or detection of data on anauxiliary service 106). The call may include any information required toexecute the task, such as parameters for execution, authenticationinformation under which to execute the task or to be used duringexecution of the task, etc.

Thereafter, at (2), the frontend 120 distributes the task for executionby the worker manager 140. While not shown in FIG. 3A, in some instancesthe frontend 120 may perform additional operations prior to distributingthe task to the worker manager 140, such as determining whethersufficient capacity exists to execute the task, queuing the task,determining accounts to which to attribute execution of the task, etc.Such operations are described in more detail in the '556 Patent.

After receiving distribution of the task, the worker manager 140, at(3), utilizes a virtual machine instance within the active pool 140 toexecute the task. Selection of a virtual machine instance may include avariety of criteria, such as whether a virtual machine instance isavailable within the active pool 140A that satisfies requirements orpreferences for executing the task (e.g., required permissions, resourceaccess, dependencies, execution environment, etc.). In the instance thatsuch a machine is not available within the active pool 140A, the workermanager 140 may interact with the warming pool manager 130 (not shown inFIG. 4) to add such a virtual machine instance to the active pool 140A,as described within the '556 Patent. In the instance that multiplevirtual machine instances are available within the active pool 140 thatsatisfy requirements or preferences for executing the task, the workermanager 140 may select between the virtual machines based on a number ofcriteria, including but not limited to load balancing of the virtualmachine instances.

During execution of the task, at (4), the worker manager 140 (e.g., byuse of a virtual machine on which the task is executing) detects thatexecution of the task has become blocked due to a dependency on aseparate asynchronous operation (an operation distinct from the task).The asynchronous operation may include, for example, a second task onthe on-demand code execution system 110 or an operation on an externalsystem, such as a network service. Because execution of the task hasbecome blocked, the task is unable to continue further processing, andyet remains active within the active pool 140A, thus inefficientlyutilizing the computing resources of the active pool 140A.

To reduce this inefficient use of resources, the worker manager 140 candetermine whether the task should be suspended until the dependencyoperation has completed. In one embodiment, the worker manager 140 mayutilize a variety of different suspension techniques based on apredicted duration of the block. Illustratively, the worker manager 140may employ a range of progressively more aggressive suspensiontechniques as the predicted duration of the block increases, such that ablocking duration of under 10 ms results in no suspension, a duration ofbetween 10 and 100 ms results in suspension of a thread of the taskwithin the virtual machine instance execution of the task, and aduration of over 100 ms results in removal of the task from itsexecution environment. The predicted blocking duration of a task may bedetermined in a variety of manners. In one embodiment, a user associatedwith a task may designate the predicted duration of a dependencyoperation, and the worker manager 140 may determine a predicted blockingduration based on how much of the predicted duration of the dependencyoperation remains at the point that the task blocks. In anotherembodiment, the worker manager 140 may assign a predicted duration of adependency operation based on historical information regarding thatdependency operation. For example, if each prior instance of thedependency operation completed in between 40 and 50 ms, the workermanager may assign a predicted duration of between 40 and 50 ms to asubsequent execution of the dependency operation (e.g., by taking anaverage, minimum, maximum, or other statistical measure of the range ofhistorical durations). Historical durations of a dependency operationmay include operations stemming from the same or different dependenttasks, as well as the same or different accounts, such that two tasks ofdifferent users that call the same dependency operation may or may notcontribute to a shared set of historical duration data for thatdependency operation. In some instances, historical durations of adependency operation may be grouped based on parameters passed to thatdependency operation, such that calls of the dependency operation with afirst set of parameters are associated with different historicaldurations than calls to the dependency operation with a second set ofparameters. Still further, historical durations of similar dependencyoperations may in some instances be grouped together, such that a set ofHTTP calls to a specific domain share historical durations for thepurposes of predicting duration of a subsequent call, or such thatmultiple related tasks (e.g., creating from a shared template, based onthe same libraries, etc.) share historical durations for the purposes ofpredicting duration of a subsequent call

For the purposes of FIG. 3A, it will be assumed that the worker manager140 assigns a predicted duration to the block of a sufficient value thatthe task should be removed from its execution environment (e.g.,container, virtual machine instance, etc.). Accordingly, the workermanager 140, at (5), saves the state of the task, to enable resuming ofthe task at a later point in time in either a new or regeneratedexecution environment.

A variety of mechanisms may be used to save the state of a task,depending on that state. For example, where the task is executing in avirtual machine instance, the worker manager 140 may save a “snapshot”(a record of the virtual machines state, including disk state, memorystate, configuration, etc.) of the virtual machine instance as a stateof the task. Similarly, where the task is executing in a container(either inside or outside a virtual machine instance), the workermanager 140 may “commit” the container, to save a current state of thecontainer as an image. While saving the state of an entire executionenvironment (e.g., a virtual machine instance or container) can ensurethat the task accurately resumes at a later point in time, it can alsobe relatively expensive from the point of view of computing resources.Moreover, if multiple tasks are currently executing in the executionenvironment, the saved state can include unnecessary and potentiallyundesirable information. An additional mechanism that can be used tosave the state of a task may be to save a state of runtime environmentexecute the task. For example, the worker manager 140 may save the stateof a node.js or Java virtual machine environment executing the task.Saving the state of a runtime environment may be associated with lowercomputing resource usage than saving the state of a full executionenvironment, and may allow other runtime environments within the sameexecution environment to continue running. A further mechanism to savethe state of the task may be to save the state of objects within thetask (e.g., variables, static objects, etc.). In some instances, savingthe state of objects may be accomplished by a compiler or interpreterthat servers to prepare the code of the task for execution. In otherinstances, saving the state of objects may be accomplished by thevirtual machine itself. For example, if the task has not yet startedprocessing (e.g., if blocking occurs very early in the task), theparameters input to the task may serve to save the state of the task.Conversely, if the task has nearly completed processing, the parametersoutput from the task may serve to save the state of the task. Thirdparty tools may also be used to inspect the memory of the executionenvironment in order to save a state (sometimes referred to as a“checkpoint”) of the task.

At (6), the worker manager 140 may remove the task from its executionenvironment, thereby eliminating the task's use of computing resourceswithin the active pool 140A. In some instances, such as where the taskwas the only task within the execution environment, the worker manager140 may further tear down or deconstruct the execution environment,further reducing computing resource use.

At (7), the worker manager 140 transmits the state information to theasync controller 160, along with information regarding the block on thetask, such as an identifier of the dependency operation on which thetask has blocked or an expected duration of the block. The asynccontroller 160, at (8), can store the retrieved state information andblocking information, such that the task can be resumed at a later time(e.g., when the dependency operation has completed or is expected tosoon complete). At (9), the async controller 160 can attach a notifierto the blocking dependency, requesting that the worker manager 140notify the async controller 160 when a blocking dependency hascompleted. For example, where the dependency operation is a task on theon-demand code execution system 110, the async controller 160 canrequest that the worker manager 140 notify the async controller 160 whenthe task has completed. Where the dependency operation is an HTTPrequest, the async controller 160 can request that the worker manager140 notify the async controller 160 when the HTTP request has completed.

The interactions of FIG. 3A are continued on FIG. 3B, where, at (10),the worker manager 140 obtains a notification that the dependencyoperation of the previously suspended task has completed.Illustratively, where the dependency operation is a second task on theon-demand code execution system 110, the worker manager 140 may obtain anotification from an execution environment of that second task that thesecond task has completed. At (11), the worker manager 140 transmits thenotification of the completed dependency to the async controller 160.The async controller 160, in turn, identifies the previously suspendedtask that is dependent on the dependency operation (e.g., from theblocking information received in the interactions of FIG. 3A) at (12),and retrieves the previously stored state information of the suspendedtask at (13). At (14), the async controller 160 transmits instructionsto the worker manager 140 to resume the previously suspended task, alongwith the state information of the task.

At (15), the worker manager 140 utilizes the state information of thepreviously suspended task to resume the task, and continue execution. Inone embodiment, the worker manager 140A may regenerate the initialexecution environment of the task, by recreating a virtual machineinstance or container in which the task was executing. However, theunderlying “host” to the execution environment may vary, enablingefficient allocation of tasks by the worker manager 140. In anotherembodiment, because the task has previously been removed from itsinitial execution environment, the worker manager 140 may in someinstances select a new execution environment for the resumed task, sucha different virtual machine instance or container. Accordingly, the taskmay be resumed in any appropriate execution environment, based on astate of the active pool 140A at the time of resuming the task. This canenable more efficient allocation of tasks, by increasing the flexibilityof task distribution after tasks have been suspended. In instances wheremultiple active pools 140A are utilized, the task may be resumed on adifferent active pool 140A than it initially executed, based on similarcriteria to that used to initially assign execution of the task to anactive pool 140A. Thus, suspension and resuming of a task by removingthe task from its initial execution environment and restoring the taskin a new or regenerated execution environment can both reduce thecomputing resources needed at the on-demand code execution system 110,by reducing the computing resources used by the task during blocking,and can increase the flexibility of the on-demand code execution system110 in distributing tasks, by enabling the execution environment of thetask to change or be re-located between suspension and resumption. Oneof skill in the art will therefore appreciate that the interactions ofFIGS. 3A and 3B represent an improvement in the operation of theon-demand code execution environment, and address technical problemsinherent within computing devices, such as the difficulty in efficientlyscheduling asynchronous tasks, and the inefficiency of maintaining ablocked task due to the computing resource usage of that task.

One of skill in the art will appreciate that the interactions of FIGS.3A and 3B may include additional or alternative interactions to thosedescribed above. For example, while some interactions are described withrespect to the worker manager 140 generally, these interactions mayoccur with respect to individual execution environments or virtualmachines within the active pool 140A managed by the worker manager. Forexample, a first virtual machine instance may implement interactions (3)through (7), while interaction (9) involves a second virtual machineinstance associated with a dependency operation. In some instances, theinteractions of FIG. 3A may involve multiple worker managers 140, suchthat interactions (3) through (7) are implemented with respect to afirst worker manager 140, and interaction (9) involves a second workermanager 140. Moreover, while the interactions of FIG. 3A are describedwith respect to both the worker manager 140 and the async controller160, in some embodiments functionalities of the async controller 160 maybe implemented within the worker manager 140 itself, such that theworker manager 140 stores a state of the task, blocking information forthe task, etc. Still further, while the interactions of FIG. 3A describeattachment of a notifier to a dependency process to enable resuming of ablocked task, the async controller 160 may additionally or alternativelyresume a blocked task based on other criteria, such as the predictedblocking duration for the task. For example, rather than using anotifier to determine when to resume a task, the async controller 160may resume a task on or before blocking of the task is expected to end(e.g., 10 ms before the block is expected to end, in order to providetime to resume the task prior to completion of the block).

While the interactions of FIGS. 3A and 3B are described with respect toan execution of a task that becomes blocked after execution of codecorresponding to the task begins, a task may additionally oralternatively become blocked prior to execution. For example, a task maydefine a dependency operation as a prerequisite, such that the task canonly begin execution after the perquisite operation has completed. Insuch instances, the worker manager 140 may save a state of the execution(which may simply refer to the inputs to the execution) as describedabove, and begin execution after the perquisite operations havecompleted, using the saved state.

Embodiments are illustratively described herein in which dependent anddependency operations have a one-to-one correspondence. Accordingly,each dependent and dependency operation may be assigned a uniqueidentifier, and the dependent operation may block or unblock base on thestatus of the dependency operation. Other configurations of theon-demand code execution system 110 are also possible. For example,dependencies may be specified by a unique identifier of a function,rather than a specific operation (e.g., execution of the function,“function( )”, rather than execution of a specific instance of thatfunction, as called by a dependent operation). Accordingly, each timethe dependency operation completes, one or more previously-blockeddependent operations may be eligible for resume. Depending on thefunctionality of the previously-blocked dependent operations, multipleoperations may be able to resume based on a single completed dependencyoperation, or each dependent operation may require that a new completionof the dependency function occur before resuming. Where the dependentoperation is a task on the on-demand code execution system 110, acreator of the task may specify whether the task requires an independentcompletion of a dependency operation, or can function based off of ashared completion of the dependency operation. Similarly, where thedependency operation is a task on the on-demand code execution system110, a creator of the task can specify whether completion of thedependency operation enables one or many dependent operations to resumeprocessing. Where less than all dependency operations are eligible toresume after completion of a dependency operation, the async controller160 may which dependent operations are eligible to resume based on anynumber of ordering algorithms, such as first-in, first-out, shortestdeadline first (for tasks associated with deadlines), etc. In someinstances, dependencies may be defined by a combination of function andparameters, such that a dependent task is dependent on a function beingcalled with a specific set parameters, no parameters, etc.

While the present application enables efficient handling of blockedtasks due to asynchronous dependencies, the present application furtherenables efficient scheduling of asynchronous task executions, even innon-blocking situations. Specifically, embodiments of the presentapplication can operate to predict a “deadline” at which the result ofan asynchronous task execution will be required, and to scheduleexecution of the asynchronous task based on that deadline. Suchscheduling can enable load balancing or time-shifted use of computingresources within the on-demand code execution system 110, thusincreasing the overall efficiency of the system. For example, where afirst task execution calls for execution of a second taskasynchronously, but the result of the second task execution is notexpected to be needed for a relatively long period of time, embodimentsof the present application can enable execution of the second task to bedelayed until the result of the second task execution is required,thereby enabling the second task to execute at any efficient time priorto a deadline, such as when the on-demand code execution environment 110has excess computing capacity.

Illustrative interactions for scheduling asynchronous task executionsbased on deadlines are described in FIGS. 4A through 4C. Specifically,FIG. 4A depicts illustrative interactions for detecting a call forasynchronous execution of a task, FIG. 4B depicts illustrativeinteractions for processing a queue of asynchronous task executionsbased on associated deadlines, and FIG. 4C depicts illustrativeinteractions for retrieving results of a completed asynchronous taskexecution.

The interactions of FIG. 4A begin at (1), where a user device 102submits to the frontend 120 a call to a task on the on-demand codeexecution system. As noted above, submission of a call may includetransmission of specialized data to the frontend 120, such as a HTTPpacket or API call referencing the task alias. While the interactions ofFIG. 4A are described as including an explicit call to the task by theuser device 102, calls to the task may occur in a variety of manners,including submission of a call by auxiliary services 106 (not shown inFIG. 4A) or generation of a call by the on-demand code execution system110 (e.g., based on a rule to call the alias when specific criteria aremet, such as elapsing of a period of time or detection of data on anauxiliary service 106). The call may include any information required toexecute the task, such as parameters for execution, authenticationinformation under which to execute the task or to be used duringexecution of the task, etc.

Thereafter, at (2), the frontend 120 distributes the task for executionby the worker manager 140. While not shown in FIG. 4A, in some instancesthe frontend 120 may perform additional operations prior to distributingthe task to the worker manager 140, such as determining whethersufficient capacity exists to execute the task, queuing the task,determining accounts to which to attribute execution of the task, etc.Such operations are described in more detail in the '556 Patent.

At (3), the worker manager 140 detects a call to asynchronously executeanother task on the on-demand code execution system 110, which mayillustratively correspond to a call to a different task, or to a secondexecution of the same task. For ease of description within FIGS. 4Athrough 4C, the asynchronously called task will be referred to as a“promise.” While the term “promise” is sometimes used to refer to codethat will later provide some return value (often referred to as a“future”), the use of the term herein does not necessarily imply thatthe asynchronously called task will return a value. Rather, the term“promise,” as used herein, is intended to refer to a call to a task thatis expected to complete some functionality used by the calling task,which may include returning a value, updating an external service (e.g.,a database), or other functionalities used by tasks on the on-demandcode execution environment 110. In one embodiment, a creator of codecorresponding to a task may designate a call to another task as a“promise.” In another embodiment, the worker manager 140 may detect acall to a promise by detecting that a call to asynchronously executeanother task has occurred, and that a result of that task will not berequired for at least a threshold duration, which may be a staticduration (e.g., 100 ms) or a variable duration (e.g., at least 50 mslonger than the asynchronously called task is expected to take tocomplete, which may be determined based on historical data regardingexecution of the task). The duration between when a promise is calledand when completion of the promise is expected to be required may bedefined by a creator of the code for the calling task, or determined bythe worker manager 140. Illustratively, the worker manager 140 maydetermine a point in code of a calling task at which a result of apromise is expected by detecting a reference to a result of the promisewithin the code, or detecting a point in the code specified by a creatorof the calling task as dependent on the promise. The worker manager 140may then estimate the duration between a call to the promise and thesubsequent reference point based on prior historical data regardingprior executions of the calling task or related tasks (e.g., creatingfrom a shared template, based on the same libraries, etc.), by summingexpected durations of each function called within the calling taskbetween a call to the promise and the subsequent reference point (wherethe duration of each function may itself be based on historical dataregarding calls to the function), by estimating the duration based ontotal lines of code, etc.

In the instance that completion of the promise is not estimated to berequired for at least a threshold amount of time, the worker manager 140can, at (4), establish a deadline for the promise. In one embodiment,the deadline can be set to the point in time at which completion of thepromise is expected to be required. In another embodiment, the deadlinecan decreased to account for an estimated time needed to completeexecution of the promise (e.g., taking into account delays required toinitialize execution of the function on the on-demand code executionenvironment, store results, etc.). While deadlines are describedillustratively as based on predicted execution time, creators of tasksmay additionally or alternatively specify deadlines manually. Forexample, a creator of a task may, at the time that a promise is called,designate the promise as having a specific deadline (e.g., 100 ms) orhaving a range of deadlines (e.g., short, medium, or long) that theon-demand code execution environment may associated with specificdeadlines.

Thereafter, at (5), the worker manager 140 transmits an indication ofthe promise and associated deadline to the async controller 160, whichcan be configured to schedule execution of the promise based on thedeadline. At (6), the async controller 160 enqueues the promise forsubsequent execution based on the associated deadline. In this regard,the async controller 160 may utilize a variety of scheduling algorithmsto enqueue promises based on deadlines, such as an earliest deadlinefirst algorithm, work-conserving scheduling, etc.

Illustrative interactions for processing a set of queued promises aredescribed with reference to FIG. 4B. Specifically, at (1), the asynccontroller 160 can process the promise queue to execute tasks on thequeue in an order determined based on associated deadlines. For a givenpromise, the async controller 160 can determine an appropriate time tocall execution of the promise, and at (2), call to the worker manager140 for execution of the promise. Appropriate times to call forexecution of a promise may in some instances be based on a capacity ofthe worker manager 140 to execute tasks. For example, the asynccontroller 160 may wait to call for execution of a promise until pointwhen the active pool 140A has excess capacity. In other instances, theasync controller 160 may attempt to limit the total number of promisesexecuting at any given time, or the number of calls per second toexecute promises. Still further, the async controller 160 may attempt toprocess the queue such that promises on the queue complete before theirassociated deadlines. Additionally or alternatively, the queueing ofeach promise may be managed at least in part on a configuration of anunderlying account associated with execution of the promise. Forexample, if an account is configured such that no more than n tasks areexecuting at a given time, a promise associated with the account may bedequeued and executed at a time that less than n tasks associated withthe account are executing. In some instances, promises on the queue maybe processed “lazily,” such that they are called either after completionof the promise is required by a calling task, or at the last otherwisesuitable time such that the promise is expected to complete processingprior to completion of the promise being required by a calling task.

After receiving a call to execute the promise the worker manager 140, at(3), executes the promise. Illustratively, the worker manager 140 canexecute the promise in the same manner as other tasks on the on-demandcode execution system 110, such as by selecting a most appropriateexecution environment for the task and executing code of the task withinthe execution environment. In some instances, the worker manager 140 mayselect an execution environment for the promise based on a taskdependent on the promise (e.g., such that both the promise and thedependent task execute in the same environment, on the same host device,etc.).

At (4), the worker manager 140 returns a result of the promise'sexecution to the async controller 160. In one embodiment, the result maysimply be an indication that the promise has executed successfully. Inanother embodiment, the result may be an output of the promise, such asa return value. At (5), the async controller 160 stores a result of thepromise (e.g., in the promises data store 164).

Illustrative interactions for enabling tasks to utilize results of apromise are described with reference to FIG. 4C. Specifically, for thepurposes of FIG. 4C, it will be assumed that a task is executing on theactive pool 140A, and has previously called for execution of a promise,as described in FIG. 4A. It will further be assumed that the asynccontroller 160 has managed execution of that promise, as described inFIG. 4B. Accordingly, at (1), the worker manager 140 detects that thetask has requested to fulfill the promise (e.g., reached a point duringexecution such that completion of the promise is required). At (2), theworker manager 140 transmits a request to the async controller 160 for aresult of the promise (e.g., a return value of the promise, anindication that the promise has completed execution successfully, etc.).The async controller 160, in turn, retrieves a result of the promise at(3), and returns the result to the worker manager 140 at (4).

Thereafter, at (5), the worker manager 140 passes a result of thepromise's execution to the dependent task, enabling the task to continueexecution. Accordingly, the dependent task can be expected to executewith little or no delay due to the promise, while still enabling theon-demand code execution system 110 to schedule execution of the promiseaccording to the state of that system 110, thus increasing theefficiency of computing resource use within the on-demand code executionsystem 110.

One of skill in the art will appreciate that the interactions of FIG. 4Athrough 4C may include additional or alternative interactions to thosedescribed above. For example, while some interactions are described withrespect to the worker manager 140 generally, these interactions mayoccur with respect to individual execution environments or virtualmachines within the active pool 140A managed by the worker manager.Moreover, some or all of the functionalities ascribed to the asynccontroller 160 may be implemented directly within the worker manager140. For example, rather than return a result of a promise's executionto the async controller 110, the worker manager 140 may itself store theresult of the promise's execution, or may pass that result to anexecution environment of a call dependent on the promise's execution.Similarly, while FIG. 4C is described as a “pull” model, such that theworker manager 140 retrieves a result of a promise's execution accordingto the requirements of a dependent task, embodiments of the disclosuremay utilize a “push” model, such that a result of the promise'sexecution is provided to an execution environment of a dependent taskwithout requiring that execution environment to issue a query for theresult. In some instances, the ordering of interactions described inFIGS. 4A through 4C may be modified. For example, in some instances, asingle dependency operation may satisfy dependencies from multipledependent operations. As such, when a dependent operation calls apromise also previously called by another dependent operations, thepromise may have already been fulfilled. Accordingly, rather thanenqueing the promise and deadline (as described above with reference tointeraction (6) of FIG. 4A), the async controller 160 may simply returna result of the promise to the worker manager 140. As a further example,in some instances, processing the promise queue according to thedeadlines of promises may result in instances where a promise result isrequested (e.g., interaction (2) of FIG. 4C) before the promise has beencompleted (e.g., via the interactions of FIG. 4B). In such instances, arequest to retrieve a promise result may cause the promise to beexecuted. Accordingly, the interactions of FIG. 4B may occur asintervening interactions, during the interactions of FIG. 4C.

As discussed above, dependencies between operations may be specified byspecific reference to individual executions, general references tofunctions, or references to an execution of a function with specifiedparameters. The interactions of FIG. 4C may therefore be modified toaddress potential one-to-many or many-to-many mappings between dependentand dependency operations. For example, where multiple dependentoperations call the same promise function (e.g., with the same ordifferent parameters), the async controller 160 may enqueue multipleinstances of that promise together, and utilize the same executionenvironment (or different execution environments on the same virtualmachine instance) to execute the promise function, thereby increasingthe efficiency of the function. Moreover, when completion of a promisefunction occurs, the async controller 160 may select which dependentoperations should be notified of such completion (e.g., all functions, asingle function, a specified number of functions, etc.), as determinedby either the configuration of the dependent operations, theconfiguration of the promise, or both. Illustratively, where less thanall dependent operations should be notified of completion of thepromise, the async controller 160 may which dependent operations shouldbe notified based on any number of ordering algorithms, such asfirst-in, first-out, shortest deadline first (for tasks associated withdeadlines), etc.

With reference to FIG. 5, a block diagram depicting an illustrativeroutine 500 for handling execution of asynchronous tasks on theon-demand code execution environment 110 will be described. The routine500 begins at block 502, where the on-demand code execution system 110(e.g., via a frontend 120) receives a call to a task. At block 504, theon-demand code execution environment 110 (e.g., via a worker manager140) proceeds to execute the task, as described in more detail in the'556 Patent.

At block 506, the on-demand code execution system 110 determines whetherthe executing task has made a call to a promise (e.g., an asynchronouslyexecuting task whose completion is not required by the calling task forat least a threshold duration). If so, the routine 500 proceeds toimplement promise handling routine 600. As is described below, thepromise handling routine 500 can enable the promise to be queued forexecution at the on-demand code execution system 110 in an efficientmanner, such that the promise is expected to complete before or near thetime that the calling task requires the completion, but can be otherwisescheduled according to the state of the on-demand code execution system110. Thereafter, the routine returns to block 504.

If no call to a promise has been made, the routine 500 continues toblock 510, where the on-demand code execution system 110 determineswhether the task has become blocked, awaiting completion of anasynchronous operation (such as a second task or operation of anexternal service). If so, the routine 500 proceeds to implement blockhandling routine 700, which, as described below, enables the task to besuspended and removed from an execution environment, and to be resumedafter or shortly before a dependency has completed. In some instances,routine 700 may only be implemented if the task is expected to beblocked for over a threshold amount of time (e.g., over 100 ms).Thereafter, the routine returns to block 504.

If the routine has not been blocked, the routine 500 continues to block514, which functions to pass the routine 500 back to block 504, so longas execution continues. When execution halts, the routine 500 passes toblock 516, and the routine 500 ends.

As can be seen from the routine 500, while handling of blocked executionand handling of promises are sometimes described separately in thepresent disclosure, both functionalities may be implemented inconjunction. For example, where execution of a task calls a promise, andthat promise fails to execute by the time required at the calling task(e.g., due to overloading of the on-demand code execution system 110),the calling task may become blocked, and be suspended by the on-demandcode execution system 110. In some instances, other functionalities maybe implemented. For example, where a hierarchy of dependencies existsbetween multiple tasks, such that a “tree” of blocked tasks exists, theon-demand code execution system 110 may order execution of the tasksaccording to their dependencies, such that each blocked task issuspended until dependency tasks have completed or are expected toshortly complete. In some instances, the on-demand code execution system110 may cause multiple tasks within a “tree” to be executed by the sameexecution environment or same physical computing device, to reduceintercommunication times among the tasks. In other instances, theon-demand code execution system 110 may execute tasks within the treeacross multiple execution environments or physical computing devices, inorder to process the tree of tasks at least partially in parallel.

With reference to FIG. 6, an illustrative routine 600 for handling callsto promises in the on-demand code execution system 110 will bedescribed. The routine may be implemented, for example, in conjunctionwith the asynchronous task handling routine 500 of FIG. 5. The routine600 begins at block 602, where the on-demand code execution system 110receives a call to a promise (e.g., from another task executing on theon-demand code execution system 110).

At block 604, the on-demand code execution system 110 determines adeadline associated with the promise. Illustratively, the deadline canbe set to the point in time at which completion of the promise isexpected to be required. As discussed above, that point in time can beestablished by a creator of a calling task, or determined by theon-demand code execution system 110 based on historical executions ofthe calling task. Illustratively, the on-demand code execution system110 may determine a point in code of a calling task at which a result ofa promise is expected by detecting a reference to a result of thepromise within the code, or detecting a point in the code specified by acreator of the calling task as dependent on the promise. The on-demandcode execution system 110 may then estimate the duration between a callto the promise and the subsequent reference point based on priorhistorical data regarding prior executions of the calling task, bysumming expected durations of each function called within the callingtask between a call to the promise and the subsequent reference point(where the duration of each function may itself be based on historicaldata regarding calls to the function), by estimating the duration basedon total lines of code, etc. The on-demand code execution system 110 maythen establish the estimated deadline based on the length of timebetween the call to the promise and the time at which the subsequentreference to the promise is expected to occur during execution of thetask.

At block 606, the on-demand code execution system 110 enqueues thepromise for execution based on the deadline. In this regard, theon-demand code execution system 110 may utilize a variety of schedulingalgorithms to enqueue promises based on deadlines, such as an earliestdeadline first algorithm, work-conserving scheduling, etc.

At block 608, the on-demand code execution system 110 executes thepromise, with timing dependent on processing of the queue of promises.Illustratively, on-demand code execution system 110 may wait to call forexecution of the promise until point when the active pool 140A hasexcess capacity. In other instances, the on-demand code execution system110 may attempt to limit the total number of promises executing at anygiven time, or the number of calls per second to execute promises. Stillfurther, the on-demand code execution system 110 may attempt to processthe queue such that promises on the queue complete before theirassociated deadlines. Additionally or alternatively, the queueing ofeach promise may be managed at least in part on a configuration of anunderlying account associated with execution of the promise. Forexample, if an account is configured such that no more than n tasks areexecuting at a given time, a promise associated with the account may bedequeued and executed at a time that less than n tasks associated withthe account are executing. In some instances, promises on the queue maybe processed “lazily,” such that they are called either after completionof the promise is required by a calling task, or at the last otherwisesuitable time such that the promise is expected to complete processingprior to completion of the promise being required by a calling task.

At block 610, the on-demand code execution system 110 returns a resultof the promise to the calling task. In some instances, a result may bereturn directly to the calling task. In other instances, the result maybe stored and made available to the calling task on request (e.g., basedon a reference to the calling within executing code of the tasks). Theroutine 600 can then end at block 612.

With reference to FIG. 7, an illustrative routine 700 for handlingblocked executions in the on-demand code execution system 110 based onasynchronous operations will be described. The routine 700 may beimplemented, for example, in conjunction with the asynchronous taskhandling routine 500 of FIG. 5. For the purposes of description of FIG.7, it will be assumed that the on-demand code execution system 110 hasbegun executing a task, which is blocked due to an asynchronousoperation. The routine 700 begins at block 702, where the on-demand codeexecution system 110 saves the state of the task. As described above, avariety of strategies may be used to save the state of a task, such assaving a state of the execution environment, runtime environment, theexecuting code itself, or objects created by the code (e.g., inputs,outputs, variables, etc.).

At block 704, the on-demand code execution system 110 removes the taskfrom its current execution environment, in order to reduce the computingresources required to maintain the blocked task. For example, theon-demand code execution system 110 may halt execution of the task codeby a virtual machine instance or container, enabling the virtual machineinstance or container to continue to process other tasks. In someinstances, such as where an execution environment of the blocked task isnot needed to process other tasks, the on-demand code execution system110 may tear down or deconstruct the execution environment, furtherreducing computational load within the on-demand code execution system110.

At block 706, the on-demand code execution system 110 can attach anotifier to the dependency operation, such that the on-demand codeexecution system 110 is informed when the dependency operation completes(and therefore, when the blocked task should continue operation). Forexample, the on-demand code execution system 110 may transmit a requestto a virtual machine instance executing the dependency operation tonotify the on-demand code execution system 110 when the dependencyoperation has completed. In some instances, the dependency operation mayalready be configured to transmit such a notification (e.g., based onthe nature of the dependency operation itself), and thus, block 706 mayoccur automatically in conjunction with calling the dependencyoperation.

At block 708, the on-demand code execution system 110 receives anotification that the dependency operation has completed. Thereafter, atblock 710, the on-demand code execution system 110 can utilize thepreviously saved state of the calling, previously blocked, task torestore the task, and resume execution of the task from a point at whichit was previously blocked. In one embodiment, the on-demand codeexecution system 110 may resume the task by recreating the executionenvironment of the task. In another embodiment, the on-demand codeexecution system 110 may resume the task by placing the task into a newexecution environment, which may result in the task being executed by adifferent physical computing device within the on-demand code executionsystem 110. Because the execution environment of the task may changebetween initial execution and resumption, the on-demand code executionsystem 110 is enabled to more efficiently allocate that resumptionaccording to the resources available at the time of resumption. Afterresuming execution, the routine 700 ends at block 712.

All of the methods and processes described above may be embodied in, andfully automated via, software code modules executed by one or moregeneral purpose computers or processors. The code modules may be storedin any type of non-transitory computer-readable medium or other computerstorage device. Some or all of the methods may alternatively be embodiedin specialized computer hardware.

Conditional language such as, among others, “can,” “could,” “might” or“may,” unless specifically stated otherwise, are otherwise understoodwithin the context as used in general to present that certainembodiments include, while other embodiments do not include, certainfeatures, elements and/or steps. Thus, such conditional language is notgenerally intended to imply that features, elements and/or steps are inany way required for one or more embodiments or that one or moreembodiments necessarily include logic for deciding, with or without userinput or prompting, whether these features, elements and/or steps areincluded or are to be performed in any particular embodiment.

Disjunctive language such as the phrase “at least one of X, Y or Z,”unless specifically stated otherwise, is otherwise understood with thecontext as used in general to present that an item, term, etc., may beeither X, Y or Z, or any combination thereof (e.g., X, Y and/or Z).Thus, such disjunctive language is not generally intended to, and shouldnot, imply that certain embodiments require at least one of X, at leastone of Y or at least one of Z to each be present.

Unless otherwise explicitly stated, articles such as ‘a’ or ‘an’ shouldgenerally be interpreted to include one or more described items.Accordingly, phrases such as “a device configured to” are intended toinclude one or more recited devices. Such one or more recited devicescan also be collectively configured to carry out the stated recitations.For example, “a processor configured to carry out recitations A, B andC” can include a first processor configured to carry out recitation Aworking in conjunction with a second processor configured to carry outrecitations B and C.

Any routine descriptions, elements or blocks in the flow diagramsdescribed herein and/or depicted in the attached figures should beunderstood as potentially representing modules, segments, or portions ofcode which include one or more executable instructions for implementingspecific logical functions or elements in the routine. Alternateimplementations are included within the scope of the embodimentsdescribed herein in which elements or functions may be deleted, orexecuted out of order from that shown or discussed, includingsubstantially synchronously or in reverse order, depending on thefunctionality involved as would be understood by those skilled in theart.

It should be emphasized that many variations and modifications may bemade to the above-described embodiments, the elements of which are to beunderstood as being among other acceptable examples. All suchmodifications and variations are intended to be included herein withinthe scope of this disclosure and protected by the following claims.

What is claimed is:
 1. A system to manage blocking of code executions inan on-demand code execution system due to asynchronous operations,wherein the on-demand code execution system comprises a plurality ofexecution environments on which user-submitted code may execute, thesystem comprising: a non-transitory data store configured to store stateinformation regarding suspended executions of tasks on the on-demandcode execution system, wherein individual tasks are associated with codeexecutable to implement functionality corresponding to the individualtasks; and one or more processors configured with computer-executableinstructions to: obtain instructions to execute a first task associatedwith first executable code; begin execution of the first executable codewithin a first execution environment, wherein execution of the firstexecutable code calls for execution of a first dependency operation;after detecting that execution of the first executable code has becomeblocked awaiting completion of the first dependency operation: determinethat a predicted duration of blocking for the execution of the firstexecutable code satisfied a threshold value; generate state informationfor the execution of the first executable code; store the generatedstate information in the non-transitory data store; and remove theexecution of the first executable code from the first executionenvironment; and after detecting that the first dependency operation hascompleted: select a second execution environment in which to resumeexecution of the first executable code; and utilize the generated stateinformation, as stored in the non-transitory data store, to resumeexecution of the first executable code in the second executionenvironment.
 2. The system of claim 1, wherein the first executionenvironment is at least one of a virtual machine instance or acontainer.
 3. The system of claim 1, wherein the second executionenvironment is a different execution environment from the firstexecution environment.
 4. The system of claim 1, wherein the secondexecution environment is a regenerated version of the first executionenvironment.
 5. The system of claim 1, wherein the state information forthe execution of the first executable code comprises at least one of avirtual machine state, a container state, a state of memory associatedwith the execution, or a state of objects of the first executable codeduring the execution.
 6. A computer-implemented method to manageblocking of code executions in an on-demand code execution system,wherein the on-demand code execution system comprises a plurality ofexecution environments on which user-submitted code may execute, thecomputer-implemented method comprising: obtain instructions to executefirst executable code within a first execution environment of theon-demand code execution system; after detecting that execution of thefirst executable code is blocked awaiting completion of a firstdependency operation: generating state information for the execution ofthe first executable code; storing the generated state information in anon-transitory data store distinct from the first execution environment;and removing the execution of the first executable code from the firstexecution environment; and after detecting that the first dependencyoperation has completed: selecting a second execution environment inwhich to resume execution of the first executable code; and utilizingthe generated state information, as stored in the non-transitory datastore, to resume execution of the first executable code in the secondexecution environment.
 7. The computer-implemented method of claim 6further comprising: predicting a duration of blocking for the executionof the first executable code; and determining that the predictedduration of blocking for the execution of the first executable codesatisfied a threshold value.
 8. The computer-implemented method of claim7, wherein predicting a duration of blocking for the execution of thefirst executable code comprises: predicting a first length of timebetween when the execution of the first executable code called forexecution of the first dependency operation and when the execution ofthe first executable code requires completion of the first dependencyoperation; predicting a second length of time required for execution ofthe first dependency operation to complete; and assigning a differencebetween the first length of time and the second length of time as thepredicted duration of blocking for the execution of the first executablecode.
 9. The computer-implemented method of claim 8, wherein the firstlength of time is predicted based on historical executions of the firstexecutable code.
 10. The computer-implemented method of claim 8, whereinthe second length of time is predicted based on historical executions ofthe first dependency operation.
 11. The computer-implemented method ofclaim 6, wherein selecting a second execution environment in which toresume execution of the first executable code comprises selecting thesecond execution environment based at least in part on the stateinformation.
 12. The computer-implemented method of claim 6, wherein theexecution of the first executable code causes a call to execute aninstance of the first dependency operation, and wherein detecting thatthe first dependency operation has completed comprises detecting thatthe instance of the first dependency operation has completed.
 13. Thecomputer-implemented method of claim 6, wherein a plurality ofexecutions of the first executable code depend on completion of thefirst dependency operation, and wherein the method further comprises, ondetecting that the first dependency operation has completed, selectingat least one of the plurality of executions of the first executable codeto be resumed.
 14. The computer-implemented method of claim 6 furthercomprising: during execution of the first execution code, detecting acall for execution of a second dependency operation; determining adeadline for the second dependency operation based at least in part onhistorical data regarding prior executions of the first executable code;enqueuing the first dependency operation into the queue based at leastin part on the deadline; and processing the queue based at least in parton an available capacity of the on-demand code execution system toexecute operations, wherein processing the queue comprises executing thefirst dependency operation.
 15. Non-transitory computer-readable storagemedia including computer-executable instructions that, when executed bya computing system, cause the computing system to: obtain instructionsto execute first executable code within a first execution environment ofan on-demand code execution system comprising a plurality of executionenvironments; after detecting that execution of the first executablecode has become blocked awaiting completion of a first dependencyoperation: generate state information for the execution of the firstexecutable code; store the generated state information in anon-transitory data store distinct from the first execution environment;and remove the execution of the first executable code from the firstexecution environment; and after detecting that the first dependencyoperation has completed: select a second execution environment in whichto resume execution of the first executable code; and utilize thegenerated state information, as stored in the non-transitory data store,to resume execution of the first executable code in the second executionenvironment.
 16. The non-transitory computer-readable storage media ofclaim 15, wherein the computer-executable instructions further cause thecomputing system to: predict a duration of blocking for the execution ofthe first executable code; and determine that the predicted duration ofblocking for the execution of the first executable code satisfied athreshold value.
 17. The non-transitory computer-readable storage mediaof claim 16, wherein predicting the duration of blocking for theexecution of the first executable code comprises: predicting a firstlength of time between when the execution of the first executable codecalled for execution of the first dependency operation and when theexecution of the first executable code requires completion of the firstdependency operation; predicting a second length of time required forexecution of the first dependency operation to complete; and assigning adifference between the first length of time and the second length oftime as the predicted duration of blocking for the execution of thefirst executable code.
 18. The non-transitory computer-readable storagemedia of claim 15, wherein at least one of the first or second lengthsof time is predicted based on historical executions on the on-demandcode execution system.
 19. The non-transitory computer-readable storagemedia of claim 15, wherein the computer-executable instructions causethe computing system to select the second execution environment in whichto resume execution of the first executable code based at least in parton the state information.
 20. The non-transitory computer-readablestorage media of claim 15, wherein the execution of the first executablecode causes a call to execute an instance of the first dependencyoperation, and wherein detecting that the first dependency operation hascompleted comprises detecting that the instance of the first dependencyoperation has completed.
 21. The non-transitory computer-readablestorage media of claim 15, wherein a plurality of executions of thefirst executable code depend on completion of the first dependencyoperation, and wherein the computer-executable instructions cause thecomputing system to select at least one of the plurality of executionsof the first executable code to be resumed.
 22. The non-transitorycomputer-readable storage media of claim 15, wherein thecomputer-executable instructions further cause the computing system to:during execution of the first execution code, detect a call forexecution of a second dependency operation; determine a deadline for thesecond dependency operation based at least in part on historical dataregarding prior executions of the first executable code; and execute thefirst dependency operation based at least in part on the deadline and anavailable capacity of the on-demand code execution system to executeoperations.